<?php

function fun_matlab($name, $args, $return) {
	// process command in matlab and update state
	$GLOBALS['compile-scripts'][] = $name;
	$args_c = array();
	foreach($args as $arg){
		if(!in_array($arg,$GLOBALS['compile-args'])){
			$GLOBALS['compile-args'][] = $arg;
			$create = true;
		}
		$a_ = array_search($arg,$GLOBALS['compile-args']);
		$a_ = "arg_".$a_;
		$args_c[] = $a_;
		if($create){
			$GLOBALS['compile-stack'][] = "{$a_} = {$arg};";
		}
	}
	$GLOBALS['compile-stack'][] = "{$return} = $name(".implode(",",$args_c).");";
}